package com.gitee.wsl.struct.command.model.parameters.arguments

interface ArgumentTransform<AllT, ValueT> {
    /** Called in [finalize] to transform each value provided to the argument. */
    val transformValue: ArgValueTransformer<ValueT>

    /** Called in [finalize] to transform the list of values to the final type. */
    val transformAll: ArgCallsTransformer<AllT, ValueT>

    /** Called after all parameters have been [finalize]d to validate the result of [transformAll] */
    val transformValidator: ArgValidator<AllT>
}

/** A callback that transforms a single value from a string to the value type */
typealias ArgValueTransformer<T> = ArgValueConverter<String, T>

/** A callback that transforms a single value from one type to another */
typealias ArgValueConverter<InT, ValueT> = ArgumentTransformContext.(InT) -> ValueT

/** A callback that transforms all the values into the final argument type */
typealias ArgCallsTransformer<AllT, EachT> = ArgumentTransformContext.(List<EachT>) -> AllT

/** A callback validates the final argument type */
typealias ArgValidator<AllT> = ArgumentTransformContext.(AllT) -> Unit

@PublishedApi
internal fun <T : Any> defaultAllProcessor(): ArgCallsTransformer<T, T> = { it.single() }

@PublishedApi
internal fun <T> defaultValidator(): ArgValidator<T> = {}